﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Ftp.cs" company="DHGMS Solutions">
//   2004-2012 DHGMS Solutions. Some Rights Reserved. Licensed under GNU General Public License version 2 (GPLv2)
// </copyright>
// <summary>
//   Unit tests for FTP extensions
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using Dhgms.TplHelper.Helpers;

namespace TestDhgms.TplHelperTest.Model.Helper
{
    using AlexPilotti.FTPS.Client;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Unit tests for FTP extensions
    /// </summary>
    [TestClass]
    public class Ftp
    {
        /// <summary>
        /// Unit tests for the GetDirectoryExists method
        /// </summary>
        [TestClass]
        public class GetDirectoryExistsMethod
        {
            /// <summary>
            /// Test to make sure the method succeeds when a folder doesn't exist
            /// </summary>
            [TestMethod]
            public void ShouldSucceedDoesntExist()
            {
                FTPSClient ftpsClient = new FTPSClient();

                ftpsClient.Connect("127.0.0.1", ESSLSupportMode.ClearText);
                
                const string CurrentDir = "/";
                const string WantedSubDirectory = "missingsubdir";
                var result = FtpHelper.GetDirectoryExists(ftpsClient, CurrentDir, WantedSubDirectory);
                Xunit.Assert.Equal(false, result);
            }
        }

        /// <summary>
        /// Unit tests for the SetCurrentDirectory method
        /// </summary>
        [TestClass]
        public class SetCurrentDirectoryMethod
        {
            /// <summary>
            /// Test to make sure the method succeeds
            /// </summary>
            [TestMethod]
            public void ShouldSucceedCreateSubdir()
            {
                FTPSClient ftpsClient = new FTPSClient();

                ftpsClient.Connect("127.0.0.1", ESSLSupportMode.ClearText);

                const string CurrentDir = "/";
                const string WantedSubDirectory = "makemissingsubdir";
                FtpHelper.SetCurrentDirectory(ftpsClient, CurrentDir + WantedSubDirectory, true);
            }

            /// <summary>
            /// Test to make sure the method succeeds
            /// </summary>
            [TestMethod]
            public void ShouldSucceedCreateMultipleLevels()
            {
                FTPSClient ftpsClient = new FTPSClient();

                ftpsClient.Connect("127.0.0.1", ESSLSupportMode.ClearText);

                const string CurrentDir = "/";
                const string WantedSubDirectory = "firstlevel/secondlevel/thirdlevel";
                FtpHelper.SetCurrentDirectory(ftpsClient, CurrentDir + WantedSubDirectory, true);
            }
        }
    }
}
